﻿using System;
using SnakeGame.Lesson1;

namespace SnakeGame.Lesson2
{
    internal abstract class StartOrEndBaseScene : ISceneUpdate
    {
        protected int nowSceneIndex = 0;
        protected string title;
        protected string strOne;
        public abstract void PrassEnterToDo();

        public void Update()
        {
            // 开始和结束场景的更新逻辑
            // 设置字体颜色
            Console.ForegroundColor = ConsoleColor.White;
            // 显示标题
            Console.SetCursorPosition(Game.width / 2 - title.Length / 2, 5);
            Console.Write(title);
            // 显示下方的选项
            Console.SetCursorPosition(Game.width / 2 - strOne.Length / 2, 8);
            Console.ForegroundColor = nowSceneIndex == 0 ? ConsoleColor.Green : ConsoleColor.White;
            Console.Write(strOne);
            Console.SetCursorPosition(Game.width / 2 - 2, 10);
            Console.ForegroundColor = nowSceneIndex == 1 ? ConsoleColor.Green : ConsoleColor.White;
            Console.Write("Exit");

            // 检测输入
            switch (Console.ReadKey(true).Key)
            {
                case ConsoleKey.W:
                    nowSceneIndex = 0;
                    break;

                case ConsoleKey.S:
                    nowSceneIndex = 1;
                    break;

                case ConsoleKey.Enter:
                    PrassEnterToDo();
                    break;
            }
        }
    }
}